function loginfn(){
	//此处没必要过滤，允许重复登录，避免前端登录信息，在后端session过期
//  if (window.localStorage){
//    var carman=localStorage.getItem("loginInfo");
//    if(carman){
//      popFaild("您已登录，请勿重复登录");
//      return false;
//    }
//  }

  var phoneno=$("#lgphoneno").val();
  var password=$("#lgpassword").val();
  if(phoneno==""){
    popFaild("请输入手机号码");
    return false;
  }
  if(password==""){
    popFaild("请输入密码");
    return false;
  }

  $.getJSON(loginServer.getLoginReq(phoneno,password),function(data){
    if(data.success==true){
      //console.log(data);
      popSucc(data.msg);
      if (window.localStorage){
        localStorage.setItem("loginInfo",data.obj.telephone);
        //存储是否有专属车位 -- Krazy Chen 2015/07/06
        localStorage.setItem("spacialCarSite",data.obj.vip);
        localStorage.setItem("parkNos",data.obj.parkNo);
        $("#specailNumber").html(localStorage.getItem("parkNos"));
      }
      $("#username").html(data.obj.telephone);
      $("#loginn").click();
      getParkingInfo();
      removeMainheaderRegs();
      showMainAFooter();
      isShowSpacialCar();
    }else{
      popFaild(data.msg);
    }
  });
}

function getValCodeFun(){
  var phoneno=$("#regphoneno").val();
  if(phoneno==""){
    popFaild("请输入手机号码");
    return false;
  }
  $.getJSON(validationServer.getValReq(phoneno),function(data){
    if(data.success==true){
     //console.log(data);
     //popSucc(data.msg);
     popSucc("验证码:"+data.obj.toString());
     $("#regvalh").val(data.obj.toString());
    }else{
      popFaild(data.msg);
    }
  });
}

function registerFn(){
  //register server
  var phoneno=$("#regphoneno").val();
  var regval=$("#regvalidation").val();
  var regvalh=$("#regvalh").val();
  var password=$("#regpassword").val();
  if(phoneno==""){
    popFaild("请输入手机号码");
    return false;
  }
  if(password==""){
    popFaild("请输入密码");
    return false;
  }
  if(regval!=regvalh){
    popFaild("请输入正确的验证码");
    return false;
  }
  $.getJSON(registerServer.getRegisterReq(phoneno,password,regval),function(data){
    if(data.success==true){
      //console.log(data);
      popSucc(data.msg);
      //login
      $.getJSON(loginServer.getLoginReq(phoneno,password),function(data){
        if(data.success==true){
          //console.log(data);
          if (window.localStorage){
            localStorage.setItem("loginInfo",data.obj.telephone.toString());
          }
        }
      });
      $("#username").html(data.obj.telephone);
      $("#regsn").click();
    }else{
      popFaild(data.msg);
    }
  });
}

function updateInfoFn(){
  var phoneno=$("#username").html();
  var namen=$("#namen").val();
  var sex=$("#sex").val();
  var carNo=$("#carNo").val();
  var engNo=$("#engNo").val();

  $.getJSON(updateInfServer.getUpdateInfReq(phoneno,sex,namen,carNo,engNo),function(data){
    if(data.success==true){
     //console.log(data);
     popSucc(data.msg);
     $("#ingoreButton").click();
    }else{
      popFaild(data.msg);
    }
  });
}

function logoutFn(){
  var phoneno=""; 
  if (window.localStorage){
    var carman=localStorage.getItem("loginInfo");
    phoneno=carman;
    if(!carman){
      popFaild("您未登录，请先登录");
      return false;
    }
  }

  $.getJSON(logoutServer.getLogoutReq(phoneno),function(data){
    if(data.success==true){
      //console.log(data);
      popSucc(data.msg);
      localStorage.removeItem("loginInfo");
      localStorage.removeItem("spacialCarSite");
      localStorage.removeItem("parkNos");
      $("#username").html("未登录");
      $("#logoutn").click();
      $.afui.drawer.hide("leftMenu");
//      if (window.localStorage){
//        var carman=localStorage.removeItem("loginInfo");
//      }
      resetAll();
    }else{
      popFaild(data.msg);
    }
  });
}
